﻿using hyjx;
using hyjx.bind;
using MixerReport.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MixerReport.Models
{
    /// <summary>
    /// 筛选模型
    /// </summary>
    public class FilterModel : BindableBase
    {
        /// <summary>
        /// 创建一个新的筛选模型
        /// </summary>
        public FilterModel() 
        {
            if(App.Mixers != null)
            {
                foreach (var item in App.Mixers)
                {
                    MixerNames.Add(item.DeviceCode, item.DeviceName);
                }
                SelectedMixerName = MixerNames.First();
            }

            //if(App.Materials != null)
            //{
            //    Materials.Add(MixerReportConstants.Eng_All, MixerReportConstants.Chs_All);
            //    foreach (var item in App.Materials)
            //    {
            //        Materials.Add(item.Name, item.Name);
            //    }
            //    SelectedMaterial = Materials.First();
            //}
            
            

            SortFields.Add("RecordTime", "记录时间");
            SortFields.Add("Material", "物料");
            SelectedSortField = SortFields.First();

            OrderByFields.Add(OrderbyDirectionTypes.Ascending, "顺序");
            OrderByFields.Add(OrderbyDirectionTypes.Descending, "倒序");
            SelectedOrderByField = OrderByFields.First();
        }

        private KeyValuePair<string,string> _selectedMixerName;
        /// <summary>
        /// 搅拌机名称
        /// </summary>
        public KeyValuePair<string, string> SelectedMixerName { get { return _selectedMixerName; } set { SetProperty(ref _selectedMixerName, value); } }
        /// <summary>
        /// 搅拌机名称集
        /// </summary>
        public Dictionary<string, string> MixerNames { get; } = new Dictionary<string, string>();
        ///// <summary>
        ///// 物料集
        ///// </summary>
        //public Dictionary<string, string> Materials { get; } = new Dictionary<string, string>();

        //private KeyValuePair<string, string> _selectedMaterial;
        ///// <summary>
        ///// 选中的物料
        ///// </summary>
        //public KeyValuePair<string, string> SelectedMaterial { get {  return _selectedMaterial; } set { SetProperty(ref _selectedMaterial, value); } }

        private DateTime? _startDate;
        /// <summary>
        /// 开始日期
        /// </summary>
        public DateTime? StartDate { get { return _startDate; } set { SetProperty(ref _startDate, value);} }

        private DateTime? _endDate;
        /// <summary>
        /// 截止日期
        /// </summary>
        public DateTime? EndDate { get { return _endDate;} set { SetProperty(ref _endDate, value); } }
        /// <summary>
        /// 排序字段集
        /// </summary>
        public Dictionary<string, string> SortFields { get; } = new Dictionary<string,string>();

        private KeyValuePair<string, string> _selectedSortField;
        /// <summary>
        /// 选中的排序字段
        /// </summary>
        public KeyValuePair<string,string> SelectedSortField { get { return _selectedSortField; } set { SetProperty(ref _selectedSortField, value); } }
        /// <summary>
        /// 排序顺序集
        /// </summary>
        public Dictionary<OrderbyDirectionTypes, string> OrderByFields { get; } = new Dictionary<OrderbyDirectionTypes, string>();

        private KeyValuePair<OrderbyDirectionTypes, string> _selectedOrderByField;
        /// <summary>
        /// 选中的排序顺序
        /// </summary>
        public KeyValuePair<OrderbyDirectionTypes, string> SelectedOrderByField { get { return _selectedOrderByField; } set { SetProperty(ref _selectedOrderByField, value); } }
        /// <summary>
        /// 筛选命令
        /// </summary>
        public FilterCommand FilterCommand { get; } = new();
    }
}
